///////////////////////////////////////////////////////////
///////////////// Have an itch? Scratch it! ///////////////
///////////////////////// SCRATCH /////////////////////////
/////////////////////  A MUD  Server   ////////////////////
///////////////////// By: Jared Devall ////////////////////
/////////////////////      Thanks:     ////////////////////
/////////////////////  DIKU/Merc/ROM   ////////////////////
///////////////////// Aetas/Deus Gang  ////////////////////
/////////////////////       Beej       ////////////////////
///////////////////////////////////////////////////////////


#ifndef CREATURE_CPP
#define CREATURE_CPP

#include "definitions.h"
#include <fstream>
#include <list>
#include "creature.h"
#include "logs.h"
#include "world.h"
#include "object.h"

Creature::Creature() {
	// Secondary
	_race = 0;
	_class = 0;
	_goldheld = 0;
	_silverheld = 0;
	_pos = 0;
	_room = 0;
	_level = 0;
	_mstr = 0;
	_str = 0;
	_mdex = 0;
	_dex = 0;
	_mcon = 0;
	_con = 0;
	_mintel = 0;
	_intel = 0;
	_mwis = 0;
	_wis = 0;
	_mcha = 0;
	_cha = 0;
	_mhp = 0;
	_hp = 0;
	_mmana = 0;
	_mana = 0;
	_mmove = 0;
	_move = 0;
	_ac = 0;
	_acbash = 0;
	_acslash = 0;
	_acpierce = 0;
	_acexotic = 0;
	_hr = 0;
	_dr = 0;
	_saves = 0;
	_wimpy = 0;
	_gender = 0;
	_height = 0;
	_weight = 0;
	_witems = 0;
	_age = 0;
}

/*Creature::Creature( Creature& it ) {
	_name = it.getName();
	_race = it.getRace();
	_class = it.getClass();
	_goldheld = it.getGoldheld();
	_silverheld = it.getSilverheld();
	_pos = it.getPos();
	_room = it.getRoom();
	_level = it.getLevel();
	_mstr = it.getMstr();
	_str = it.getStr();
	_mdex = it.getMdex();
	_dex = it.getDex();
	_mcon = it.getMcon();
	_con = it.getCon();
	_mintel = it.getMintel();
	_intel = it.getIntel();
	_mwis = it.getMwis();
	_wis = it.getWis();
	_mcha = it.getMcha();
	_cha = it.getCha();
	_mhp = it.getMhp();
	_hp = it.getHp();
	_mmana = it.getMmana();
	_mana = it.getMana();
	_mmove = it.getMmove();
	_move = it.getMove();
	_ac = it.getAc();
	_acbash = it.getAcbash();
	_acslash = it.getAcslash();
	_acpierce = it.getAcpierce();
	_acexotic = it.getAcexotic();
	_hr = it.getHr();
	_dr = it.getDr();
	_saves = it.getSaves();
	_wimpy = it.getWimpy();
	_gender = it.getGender();
	_height = it.getHeight();
	_weight = it.getWeight();
	_witems = it.getWitems();
	_age = it.getAge();
	_desc = it.getDesc();
}*/

Creature::~Creature() {}

Creature& Creature::operator = ( Creature& it ) {
	_name = it.getName();
	_race = it.getRace();
	_class = it.getClass();
	_goldheld = it.getGoldheld();
	_silverheld = it.getSilverheld();
	_pos = it.getPos();
	_room = it.getRoom();
	_level = it.getLevel();
	_mstr = it.getMstr();
	_str = it.getStr();
	_mdex = it.getMdex();
	_dex = it.getDex();
	_mcon = it.getMcon();
	_con = it.getCon();
	_mintel = it.getMintel();
	_intel = it.getIntel();
	_mwis = it.getMwis();
	_wis = it.getWis();
	_mcha = it.getMcha();
	_cha = it.getCha();
	_mhp = it.getMhp();
	_hp = it.getHp();
	_mmana = it.getMmana();
	_mana = it.getMana();
	_mmove = it.getMmove();
	_move = it.getMove();
	_ac = it.getAc();
	_acbash = it.getAcbash();
	_acslash = it.getAcslash();
	_acpierce = it.getAcpierce();
	_acexotic = it.getAcexotic();
	_hr = it.getHr();
	_dr = it.getDr();
	_saves = it.getSaves();
	_wimpy = it.getWimpy();
	_gender = it.getGender();
	_height = it.getHeight();
	_weight = it.getWeight();
	_witems = it.getWitems();
	_age = it.getAge();
	_desc = it.getDesc();
	return *this;
}

// Primary
std::string& Creature::getName() {
	return this->_name;
}

void Creature::setName( std::string& name ) {
	this->_name = name;
	return;
}

// Added...
int Creature::getRace()
{
	return _race;
}

void Creature::setRace( int race )
{
	_race = race;
}

int Creature::getClass()
{
	return _class;
}

void Creature::setClass( int Class )
{
	_class = Class;
}

int Creature::getGoldheld()
{
	return _goldheld;
}

void Creature::setGoldheld( int goldheld )
{
	_goldheld = goldheld;
}

int Creature::getSilverheld()
{
	return _silverheld;
}

void Creature::setSilverheld( int silverheld )
{
	_silverheld = silverheld;
}

int Creature::getPos()
{
	return _pos;
}

void Creature::setPos( int pos )
{
	_pos = pos;
}

Room* Creature::getRoom() {
	return _room;
}

void Creature::setRoom( int number ) {
	_room = World::Instance().FindRoom( number );
}

Object* Creature::findObject( std::string keywords ) {
	for ( std::list< Object* >::iterator it = getInventory().begin(); it != getInventory().end(); it++ )
		if ( (*it)->getKeywords() == keywords || sub_str( (*it)->getKeywords(), keywords ) )
			return *it;

	return NULL;
}

int Creature::getLevel()
{
	return _level;
}

void Creature::setLevel( int level )
{
	_level = level;
}

int Creature::getMstr()
{
	return _mstr;
}

void Creature::setMstr( int mstr )
{
	_mstr = mstr;
}

int Creature::getStr()
{
	return _str;
}

void Creature::setStr( int str )
{
	_str = str;
}

int Creature::getMdex()
{
	return _mdex;
}

void Creature::setMdex( int mdex )
{
	_mdex = mdex;
}

int Creature::getDex()
{
	return _dex;
}

void Creature::setDex( int dex )
{
	_dex = dex;
}

int Creature::getMcon()
{
	return _mcon;
}

void Creature::setMcon( int mcon )
{
	_mcon = mcon;
}

int Creature::getCon()
{
	return _con;
}

void Creature::setCon( int con )
{
	_con = con;
}

int Creature::getMintel()
{
	return _mintel;
}

void Creature::setMintel( int mintel )
{
	_mintel = mintel;
}

int Creature::getIntel()
{
	return _intel;
}

void Creature::setIntel( int intel )
{
	_intel = intel;
}

int Creature::getMwis()
{
	return _mwis;
}

void Creature::setMwis( int mwis )
{
	_mwis = mwis;
}

int Creature::getWis()
{
	return _wis;
}

void Creature::setWis( int wis )
{
	_wis = wis;
}

int Creature::getMcha() {
	return _mcha;
}

void Creature::setMcha( int mcha ) {
	_mcha = mcha;
}

int Creature::getCha() {
	return _cha;
}

void Creature::setCha( int cha ) {
	_cha = cha;
}

int Creature::getMhp()
{
	return _mhp;
}

void Creature::setMhp( int mhp )
{
	_mhp = mhp;
}

int Creature::getHp()
{
	return _hp;
}

void Creature::setHp( int hp )
{
	_hp = hp;
}

int Creature::getMmana()
{
	return _mmana;
}

void Creature::setMmana( int mmana )
{
	_mmana = mmana;
}

int Creature::getMana()
{
	return _mana;
}

void Creature::setMana( int mana )
{
	_mana = mana;
}

int Creature::getMmove()
{
	return _mmove;
}

void Creature::setMmove( int mmove )
{
	_mmove = mmove;
}

int Creature::getMove()
{
	return _move;
}

void Creature::setMove( int move )
{
	_move = move;
}

int Creature::getAc()
{
	return _ac;
}

void Creature::setAc( int ac )
{
	_ac = ac;
}

int Creature::getAcbash()
{
	return _acbash;
}

void Creature::setAcbash( int acbash )
{
	_acbash = acbash;
}

int Creature::getAcslash()
{
	return _acslash;
}

void Creature::setAcslash( int acslash )
{
	_acslash = acslash;
}

int Creature::getAcpierce()
{
	return _acpierce;
}

void Creature::setAcpierce( int acpierce )
{
	_acpierce = acpierce;
}

int Creature::getAcexotic()
{
	return _acexotic;
}

void Creature::setAcexotic( int acexotic )
{
	_acexotic = acexotic;
}

int Creature::getHr()
{
	return _hr;
}

void Creature::setHr( int hr )
{
	_hr = hr;
}

int Creature::getDr()
{
	return _dr;
}

void Creature::setDr( int dr )
{
	_dr = dr;
}

int Creature::getSaves()
{
	return _saves;
}

void Creature::setSaves( int saves )
{
	_saves = saves;
}

int Creature::getWimpy()
{
	return _wimpy;
}

void Creature::setWimpy( int wimpy )
{
	_wimpy = wimpy;
}

int Creature::getGender()
{
	return _gender;
}

void Creature::setGender( int gender )
{
	_gender = gender;
}

int Creature::getHeight()
{

	return _height;
}

void Creature::setHeight( int height )
{
	_height = height;
}

int Creature::getWeight()
{
	return _weight;
}

void Creature::setWeight( int weight )
{
	_weight = weight;
}

int Creature::getWitems()
{
	return _witems;
}

void Creature::setWitems( int witems )
{
	_witems = witems;
}

int Creature::getAge()
{
	return _age;
}

void Creature::setAge( int age )
{
	_age = age;
}

std::string& Creature::getDesc( void ) {
	return _desc;
}

void Creature::setDesc( std::string desc ) {
	_desc = desc;
	return;
}

std::list< Object* >& Creature::getInventory() {
	return _inventory;
}

void Creature::add( Object* obj ) {
	_inventory.push_front( obj );
	return;
}

void Creature::remove( Object* obj ) {
	_inventory.remove( obj );
	return;
}

void Creature::Save( std::ofstream& save, Room* room ) {
	save << "// Creature data...\n";

	save << _name << '\n';
	save << _race << ' ' << _class << ' ';
	save << _goldheld << ' ' << _silverheld << ' ';
	save << _pos << ' ';
	if ( room == NULL )
		save << 0;
	else
		save << _room->GetVnum();
	save << ' ' << _level << '\n';
	save << _str << ' ' << _mstr << ' ';
	save << _dex << ' ' << _mdex << ' ';
	save << _con << ' ' << _mcon << ' ';
	save << _intel << ' ' << _mintel << ' ';
	save << _wis << ' ' << _mwis << ' ';
	save << _cha << ' ' << _mcha << ' ';
	save << _hp << ' ' << _mhp << ' ' << _mana << ' ' << _mmana << ' ' << _move << ' ' << _mmove << '\n';
	save << _ac << ' ' << _acbash << ' ' << _acslash << ' ' << _acpierce << ' ' << _acexotic << ' ';
	save << _hr << ' ' << _dr << ' ' << _saves << ' ';
	save << _wimpy << ' ' << _gender << ' ';
	save << _height << ' ' << _weight << ' ' << _witems << ' ' << _age << '\n';
	save << _desc << "$\n";
	return;
}

void Creature::Load( std::ifstream& load ) {
	char* temp = new char[2048];
	int itemp = 0;

	// pfile comment killer
	load.getline( temp, 100 );

	// load the data
	load.getline( temp, 2048 ); _name = temp;
	load >> _race >> _class;
	load >> _goldheld >> _silverheld;
	load >> _pos >> itemp >> _level;
	setRoom( itemp );
	load >> _str >> _mstr >> _dex >> _mdex >> _con >> _mcon >> _intel >> _mintel >> _wis >> _mwis >> _cha >> _mcha;
	load >> _hp >> _mhp >> _mana >> _mmana >> _move >> _mmove;
	load >> _ac >> _acbash >> _acslash >> _acpierce >> _acexotic;
	load >> _hr >> _dr >> _saves;
	load >> _wimpy >> _gender;
	load >> _height >> _weight >> _witems >> _age;
	load.get(); load.getline( temp, 2048, '$' ); _desc = temp;

	// pfile comment killers
	load.get();
	load.get();
	load.get();
	load.getline( temp, 100 );
	return;
}

std::string Creature::stringRace() {
	std::string buf;

	if ( _race == HUMAN )
		buf = "human";
	if ( _race == ELF )
		buf = "elf";
	if ( _race == DWARF )
		buf = "dwarf";
	if ( _race == SATYR )
		buf = "satyr";
	if ( _race == SPRITE )
		buf = "sprite";
	if ( _race == GNOME )
		buf = "gnome";
	if ( _race == TROLL )
		buf = "troll";
	if ( _race == GOBLIN )
		buf = "goblin";
	if ( _race == ORC )
		buf = "orc";

	return buf;
}

int Creature::intRace( std::string in ) {
	int race = 0;

	if ( in == "human" )
		race = HUMAN;
	else if ( in == "elf" )
		race = ELF;
	else if ( in == "dwarf" )
		race = DWARF;
	else if ( in == "satyr" )
		race = SATYR;
	else if ( in == "sprite" )
		race = SPRITE;
	else if ( in == "gnome" )
		race = GNOME;
	else if ( in == "troll" )
		race = TROLL;
	else if ( in == "goblin" )
		race = GOBLIN;
	else if ( in == "orc" )
		race = ORC;
	else
		race = 0;

	return race;
}

std::string Creature::stringClass() {
	std::string buf;

	if ( _class == MAGE )
		buf = "mage";
	if ( _class == CLERIC )
		buf = "cleric";
	if ( _class == NECRO )
		buf = "necro";
	if ( _class == DRUID )
		buf = "druid";
	if ( _class == ALCHEMIST )
		buf = "alchemist";
	if ( _class == WARRIOR )
		buf = "warrior";
	if ( _class == KNIGHT )
		buf = "knight";
	if ( _class == BANDIT )
		buf = "bandit";
	if ( _class == RANGER )
		buf = "ranger";
	if ( _class == VANGUARD )
		buf = "vanguard";
	if ( _class == GUARDIAN )
		buf = "guardian";
	if ( _class == SAGE )
		buf = "sage";

	return buf;
}

int Creature::intClass( std::string in ) {
	int _class = 0;

	if ( in == "mage" )
		_class = MAGE;
	else if ( in == "cleric" )
		_class = CLERIC;
	else if ( in == "necro" )
		_class = NECRO;
	else if ( in == "druid" )
		_class = DRUID;
	else if ( in == "alchemist" )
		_class = ALCHEMIST;
	else if ( in == "warrior" )
		_class = WARRIOR;
	else if ( in == "knight" )
		_class = KNIGHT;
	else if ( in == "bandit" )
		_class = BANDIT;
	else if ( in == "ranger" )
		_class = RANGER;
	else if ( in == "vanguard" )
		_class = VANGUARD;
	else if ( in == "guardian" )
		_class = GUARDIAN;
	else if ( in == "sage" )
		_class = SAGE;
	else
		_class = 0;

	return _class;

}

std::string Creature::stringGender() {
	std::string buf;

	if ( _gender == MALE )
		buf = "male";
	else if ( _gender == FEMALE )
		buf = "female";
	else
		buf = "neutral";

	return buf;
}

int Creature::intGender( std::string in ) {
	int gender = 0;

	if ( in == "male" )
		gender = MALE;
	else if ( in == "female" )
		gender = FEMALE;
	else
		gender = NEUTRAL;

	return gender;
}



#endif // #ifndef CREATURE_CPP
